# encoding: utf-8
"""
@author: 夏洛
@QQ: 1972386194
@file: a2.py
"""

import asyncio
import websockets

async def echo(websocket):
    # 使用WebSocket在客户端和服务器之间建立全双工双向连接后，就可以在连接打开时调用send()方法。
    message = 'xxx'
    await websocket.send(message)
    return True

async def recv_msg(websocket):
    while 1:
        recv_text = await websocket.recv()
        print(recv_text)

async def main_logic(websocket,path):
    await echo(websocket)
    await recv_msg(websocket)

start_server = websockets.serve(main_logic, '127.0.0.1', 8765)
asyncio.get_event_loop().run_until_complete(start_server)
asyncio.get_event_loop().run_forever()
